package com.hcc.cpwxdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hcc.cpwxdemo.dto.QyWxAppDTO;
import com.hcc.cpwxdemo.entity.QyWxApp;
import com.hcc.cpwxdemo.mapper.QyWxAppMapper;
import com.hcc.cpwxdemo.service.QyWxAppService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author hcc
 * @Date: 2020/1/16 16:11
 * @Desc: 类描述
 */
@Service
public class QyWxAppServiceImpl extends ServiceImpl<QyWxAppMapper, QyWxApp> implements QyWxAppService {

    /**
     * 根据企业id 应用id 获取 应用配置信息
     *
     * @param corpId  corpId
     * @param agentId agentId
     * @return QyWxAppDTO
     */
    @Override
    public QyWxAppDTO getDtoByCorpIdAndAgentId(String corpId, Integer agentId) {

        QyWxApp qyWxApp = new QyWxApp();
        qyWxApp.setCorpId(corpId);
        qyWxApp.setAgentId(agentId);
        return getDtoByPo(this.getOne(new QueryWrapper<>(qyWxApp)));
    }

    private QyWxAppDTO getDtoByPo(QyWxApp qyWxApp) {
        QyWxAppDTO dto = null;
        if (qyWxApp != null) {
            dto = new QyWxAppDTO();
            BeanUtils.copyProperties(qyWxApp, dto);
        }
        return dto;
    }

}
